const express = require('express')
const fs = require('fs')
const path = require('path')

const app = express()

// 声明全局中间件函数
function whiteMddd(req,res,next){
    let { url , ip } = req;
    fs.appendFileSync(path.resolve(__dirname,'./access.log'),`${url}  ${ip} \r\n`)
    // 通过
    next()
}

// 使用全局中间件
app.use(whiteMddd)

app.get('/home',(req,res)=>{
    // let { url , ip } = req;
    // fs.appendFileSync(path.resolve(__dirname,'./access.log'),`${url}  ${ip} \r\n`)
    res.send('home')
})

app.get('/carter',(req,res)=>{
    // let { url , ip } = req;
    // fs.appendFileSync(path.resolve(__dirname,'./access.log'),`${url}  ${ip} \r\n`)
    res.send('carter')
})

app.listen(3000,()=>{
    console.log('3000服务启动');
})
